package com.sure.supermarketserver.security.login;

import com.sure.supermarketserver.common.Result;
import com.sure.supermarketserver.common.TokenUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/security/login")
public class LoginAPI {

    @Resource
    private LoginService loginService;

    @PostMapping("")
    public Result login(@RequestBody LoginDto dto){
        boolean ok= loginService.checkLogin(dto);

        if (ok){
            String token= TokenUtils.loginSign(dto.getU_id(),dto.getU_pwd());
            return Result.success((Object) token);
        }
        return Result.fail(Result.ERR_CODE_BUSINESS,"账号或密码错误");
    }
}
